/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.katica.rest.services;

import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import hu.katica.rest.model.AmazonModel;
import hu.katica.rest.model.PerformanceModel;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;

/**
 * REST Web Service
 *
 */
@Path("amazon")
public class AmazonInstance {
    
    private List<AmazonModel>models;

    private void buildModels(){
        models=new ArrayList<AmazonModel>();
        for(long x=1;x<100;x++){
            models.add(new AmazonModel(x,"Name"+x,"State"+x,"PublicDNS"+x));
        }
    }
    
    public AmazonInstance() {
        buildModels();
    }

    @POST
    @Consumes("application/x-www-form-urlencoded")
    @Path("start/")
    public void startInstance(String instance) {
        System.out.println("Amazon startInstance...:"+instance);
    }

    @POST
    @Consumes("application/x-www-form-urlencoded")
    @Path("stop/")
    public void stopInstance(String instance) {
        System.out.println("Amazon stopInstance...:"+instance);
    }

    @GET
    @Produces("application/json")
    @Path("load/")
    public PerformanceModel load() {        
        System.out.println("Amazon load() started...");
        int random = (int)(Math.random()*100);
        return new PerformanceModel(random);
    }
    
    @GET
    @Produces("application/json")
    public List<AmazonModel> listInstances(@Context HttpServletResponse response) {        
        System.out.println("Amazon listInstances started...");
        return models;
    }
        
}
